<template>
	<view class="ran_king">
		<view class="title s28 familytow fblod txtali" v-if="txtShow">
			{{title}}
		</view>
		<block v-if="showOne == 3 || showOne == 4">
			<view class="list_box flex">
				<view :class="[listIndex == index ? 'active_txt' : '' ,'list_active','f500','family','s28']"
					v-for="(item,index) in list" :key="index" @click="active(index)">
					{{item.name}}
					<view class="xian" v-if="listIndex == index"></view>
				</view>
			</view>
		</block>
		<block v-if="listIndex == 2">
			<input class="uni-input-active f500 s24" v-model="screenVal" placeholder-style="color:#ccc;"
				placeholder="商家名称" @focus="boxType" />
			<view class="screen_img">
				<image class="w100 h100" src="../static/shopping/search.png" mode=""></image>
			</view>
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" v-if="flag">
				<view id="demo1" class="scroll-view-item uni-bg-red" @click="boxType">A</view>
			</scroll-view>
		</block>
		<block v-if="showTwo == 2">
			<view class="list_box flex">
				<view :class="[listIndex == index ? 'activeTwo_txt' : '' ,'list_active','f500','family','s28']"
					v-for="(item,index) in listTwo" style="margin-left: 160upx;" :key="index" @click="active(index)">
					{{item.name}}
					<view class="xianTwo" v-if="listIndex == index"></view>
				</view>
			</view>
		</block>
		<view class="listT_box flex">
			<view :class="[listTIndex == index ? 'listT_jd_box_active' : 'listT_jd_box', 'f500', 'family', 's24']"
				v-for="(item,index) in jidu" :key="index" @click="activeTwo(index)">
				{{item.name}}
			</view>
			<picker @change="bindPickerChange" :value="index" :range="array">
				<view class="listT_jd_box 'f500' 'family' 's24'">{{array[index]}}</view>
			</picker>
		</view>
		<block v-if="listTIndex == 3">

		</block>
		<view class="list_con flex flexjus" v-for="(item,index) in listData" :key="index">
			<view class="flex">
				<view class="head_tx_box">
					<image class="w100 h100" :src="item.avatar" mode=""></image>
				</view>
				<view class="sd_name_ran">
					<view class="sd_name fblod familytow s26">
						{{item.nickname?item.nickname:item.shopname?item.shopname:''}}
					</view>
					<view class="sd_ran f500 family s22">
						第{{index+1}}名
					</view>
				</view>
			</view>
			<view class="jiaqian f500 family s24">
				￥{{item.all_money||0}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "ranking",
		props: {
			title: {
				type: String,
				default: ''
			},
			userInfo: {
				type: Object,
				default: {}
			},
			list: {
				type: Array,
				default: []
			},
			listTwo: {
				type: Array,
				default: []
			},
			jidu: {
				type: Array,
				default: []
			},
			showOne: {
				type: [String, Number],
				default: 0
			},
			txtShow: {
				type: Boolean,
				default: false
			},
			showTwo: {
				type: [String, Number],
				default: 0
			}
		},
		data() {
			return {
				listIndex: 0,
				listTIndex: 0,
				array: ['选择年份'],
				index: 0,
				year: '',
				flag: false,
				listData: {}
			}
		},
		created() {
			let date = new Date()
			this.year = date.getFullYear();
			for (var i = 1; i < 50; i++) {
				this.array.push(this.year - i)
			}
			setTimeout(() => {
				return false
			}, 5000)
			this.businessRank()
		},
		methods: {
			businessRank() {
				let that = this
				that.$request({
					url: 'team/getRank',
					method: 'POST',
					data: {
						offset: 0,
						count: 10,
						type: that.listIndex == 0 ? 'rebate_ranking' : that.listIndex == 1 ? 'money_ranking' :
							'shop_ranking',
						interval: that.listTIndex == 0 ? 'quarterly' : that.listTIndex == 1 ? 'annual' :
							'previous',
						year: this.array[this.index] == '选择年份' ? '' : this.array[this.index],
						shop_name: ''
					}
				}).then(res => {
					if(res.data.code == 1) {
						this.listData = res.data.data.list.data;
					}
				})
			},
			rebateRank() {
				let that = this
				that.$request({
					url: 'team/getPartnerRank',
					data: {
						offset: 0,
						count: 10,
						type: that.listIndex == 0 ? 'rebate_ranking ' : that.listIndex == 1 ? 'money_ranking' :
							'shop_ranking',
						interval: that.listTIndex == 0 ? 'quarterly' : that.listTIndex == 1 ? 'annual' :
							'previous',
						year: this.array[this.index] == '选择年份' ? '' : this.array[this.index],
						shop_name: ''
					}
				}).then(res => {
					return false
				})
			},
			boxType() {
				this.flag = !this.flag
			},
			bindPickerChange: function(e) {
				this.index = e.detail.value
				if (this.title == '商家职员内部排行') {
					this.businessRank()
				} else {
					this.rebateRank()
				}
			},
			active(index) {
				this.listIndex = index
				if (this.title == '商家职员内部排行') {
					this.businessRank()
				} else {
					this.rebateRank()
				}
			},
			activeTwo(index) {
				this.listTIndex = index
				if (this.title == '商家职员内部排行') {
					this.businessRank()
				} else {
					this.rebateRank()
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.ran_king {
		width: 686upx;
		background: #FFFFFF;
		border-radius: 16upx 16upx 16upx 16upx;
		overflow: hidden;

		.title {
			color: #333333;
			margin-top: 32upx;
		}

		.uni-input-active {
			width: 550upx;
			height: 68upx;
			background: #FFFFFF;
			border-radius: 8upx 8upx 8upx 8upx;
			border: 2upx solid #333333;
			font-family: PingFang SC-Medium, PingFang SC;
			color: #CCCCCC;
			padding-left: 78upx;
			margin: 0 auto;
		}

		.screen_img {
			width: 40upx;
			height: 40upx;
			position: relative;
			left: 50upx;
			top: -56upx;
		}
		.scroll-Y {
			width: 610upx;
			height: 400upx;
			margin: 0 auto;
			margin-bottom: 30upx;
			border-radius: 9upx;
			background-color: #F4F5F9;
			padding: 10upx;
		}
		.list_box {
			margin-top: 38upx;
			margin-bottom: 36rpx;

			.list_active {
				color: #666666;
				margin-left: 142upx;
			}

			.list_active:nth-child(1) {
				margin-left: 38upx;
			}

			.active_txt {
				color: #EBBE87;
			}

			.activeTwo_txt {
				color: #000000;
			}

			.xian {
				width: 82upx;
				height: 6upx;
				background: #EBBE87;
				margin: 8upx auto;
			}

			.xianTwo {
				width: 82upx;
				height: 6upx;
				background: #000000;
				margin: 8upx auto;
			}
		}

		.listT_box {
			margin-left: 32upx;

			.listT_jd_box {
				padding: 4upx 14upx 4upx 14upx;
				border: 2upx solid #CBCBCB;
				border-radius: 12upx;
				margin-left: 22upx;
				color: #CBCBCB;
			}

			.listT_jd_box_active {
				padding: 4upx 14upx 4upx 14upx;
				background: #EBBE87;
				border-radius: 12upx;
				margin-left: 22upx;
				color: #FFFFFF;
			}

			.listT_jd_box:nth-child(1) {
				margin-left: 10upx;
			}

			.listT_jd_box_active:nth-child(1) {
				margin-left: 10upx;
			}
		}

		.list_con {
			width: 622upx;
			height: 134upx;
			margin: 28upx auto;
			border-top: 2upx solid #F4F5F9;
			border-bottom: 2upx solid #F4F5F9;

			.head_tx_box {
				width: 76upx;
				height: 76upx;
				border-radius: 50%;
				margin-top: 30upx;
				overflow: hidden;
			}

			.sd_name_ran {
				margin-left: 16upx;
				margin-top: 28upx;

				.sd_name {
					color: #333333;
				}

				.sd_ran {
					color: #666666;
					margin-top: 12upx;
				}
			}

			.jiaqian {
				color: #FF3F4A;
				margin-top: 40upx;
			}
		}
	}
</style>
